<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>收件人信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>收件人</label>
                        <div class="layui-input-block">
                            <input type="text" name="shouer" id="shouer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>收件人电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="shoutel" id="shoutel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>收件地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="shouaddr" id="shouaddr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>寄件信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>寄件人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=jier&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="jier"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=jier&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="jier_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款方式</label>
                        <div class="layui-input-block">
                            <select id="futype" name="futype" lay-filter="futype">
                                <option value="">请选择</option>
                                <option value="月结">月结</option>
                                <option value="现付">现付</option>
                                <option value="对方付">对方付</option>
                            </select>
                            <p class="error" id="futype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>是否工程挂账</label>
                        <div class="layui-input-block">
                            <select id="isgua" name="isgua" lay-filter="isgua">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                            <p class="error" id="isgua_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide isguashi">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=kuai_ji','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=kuai_ji','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" id="gofuer" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>快件内容</label>
                        <div class="layui-input-block">
                            <input type="text" name="nei" id="nei" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">寄件日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="jidt" id="jidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">运单号</label>
                        <div class="layui-input-block">
                            <input type="text" name="yunnum" id="yunnum" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">快递费用(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="kuaifee" name="kuaifee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联流程</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;
    var param_isturn = getQueryVariable('isturn') || 0;
    if(param_isturn > 0){
        $("#billzhan").remove();
        $("#billtutn").remove();
        $("#billsub").attr('isshen', 1);
    }
    var param_billyushen = getQueryVariable('billyushen') || 0;
    if(param_billyushen == 2){
        $("#billyushen").addClass('layui-hide');
    }


    $("#commentForm").validate({
        rules: {
            shouer: {required: true},
            shoutel: {required: true},
            shouaddr: {required: true},
            nei: {required: true},
        },
        messages:{
            shouer: {required: "请输入"},
            shoutel: {required: "请输入"},
            shouaddr: {required: "请输入"},
            nei: {required: "请输入"},
        }
    });

    
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_edit_kuai_ji, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                    if(data.advaners_info.length > 0){
                        tan_tags_init('#advaners', data.advaners_info);
                    }
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                    if(data.nexter_info.length > 0){
                        tan_tags_init('#nexter', data.nexter_info);
                    }
                }
                if(data.flowrelas_info.length > 0){
                    set_choose_btn_more('flowrelas',data.flowrelas_info);
                }



                if(res.data.jier_info.length > 0){
                    tan_tags_init('#jier', res.data.jier_info);
                }



                if(data.isgua == '是'){
                    $(".isguashi").removeClass('layui-hide');

                    var engininfo = res.data.engininfo;
                    if(engininfo){
                        set_choose_btn('enginid',engininfo.id,engininfo.name);
                        $("#gofuer").val(engininfo.gofuer);
                    }
                }


                $("#shouer").val(data.shouer);
                $("#shoutel").val(data.shoutel);
                $("#shouaddr").val(data.shouaddr);
                $("#futype").val(data.futype);
                $("#isgua").val(data.isgua);
                $("#nei").val(data.nei);
                $("#jidt").val(data.jidt);
                $("#yunnum").val(data.yunnum);
                $("#kuaifee").val(data.kuaifee);
                $("#explain").val(data.explain);


                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('select(futype)', function(data){
            if(data.value == ''){
                $('#futype_error').show().text('请选择');
                $('#futype_error').parent().find('input').addClass('select_error');
            }else{
                $('#futype_error').hide();
                $('#futype_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(isgua)', function(data){
            if(data.value == ''){
                $('#isgua_error').show().text('请选择');
                $('#isgua_error').parent().find('input').addClass('select_error');
            }else{
                $('#isgua_error').hide();
                $('#isgua_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == '是'){
                $(".isguashi").removeClass('layui-hide');
            }else{
                $(".isguashi").addClass('layui-hide');
            }

        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.isshen = $(this).attr('isshen') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');

            data.field.jier = tan_tags_getvalue("#jier", 'user');
            data.field.enginid = get_choose_val('enginid');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                if(!data.field.jier){
                    $("#jier").parents('.tanxian').addClass('tanerror');
                    $('#jier_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#jier").parents('.tanxian').removeClass('tanerror');
                    $('#jier_tanerror').text('');
                }

                if(data.field.futype == ''){
                    $('#futype_error').show().text('请选择');
                    $('#futype_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#futype_error').hide();
                    $('#futype_error').parent().find('input').removeClass('select_error');
                }
                if(data.field.isgua == ''){
                    $('#isgua_error').show().text('请选择');
                    $('#isgua_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#isgua_error').hide();
                    $('#isgua_error').parent().find('input').removeClass('select_error');
                }

                if(data.field.isgua == '是'){
                    formValid('enginid');
                    if(data.field.enginid == undefined || !data.field.enginid){
                        validRes = false;
                    }
                }

                if(!validRes){return false;}
            }


            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);
            public_flow_submit(data.field, ask_flowdata_add_kuai_ji, ask_flowdata_edit_kuai_ji, $(this).attr('but'));
            return false;
        });

    });




</script>
</body>
</html>
